home *** CD-ROM | disk | FTP | other *** search
/ Programming a Multiplayer FPS in DirectX / Programming a Multiplayer FPS in DirectX (Companion CD).iso / DirectX / dxsdk_oct2004.exe / dxsdk.exe / Samples / C++ / Common / DXUTSettingsDlg.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2004-09-28  |  49.2 KB  |  1,297 lines

  1. //--------------------------------------------------------------------------------------
  2. // File: DXUTSettingsDlg.cpp
  3. //
  4. // Dialog for selection of device settings 
  5. //
  6. // Copyright (c) Microsoft Corporation. All rights reserved
  7. //--------------------------------------------------------------------------------------
  8. #include "dxstdafx.h"
  9.  
  10.  
  11. //--------------------------------------------------------------------------------------
  12. // Internal functions forward declarations
  13. //--------------------------------------------------------------------------------------
  14. WCHAR* DXUTPresentIntervalToString( UINT pi );
  15. WCHAR* DXUTMultisampleTypeToString(D3DMULTISAMPLE_TYPE MultiSampleType);
  16. WCHAR* DXUTD3DDeviceTypeToString(D3DDEVTYPE devType);
  17. WCHAR* DXUTVertexProcessingTypeToString(DWORD vpt);
  18.  
  19.  
  20. //--------------------------------------------------------------------------------------
  21. // Global state
  22. //--------------------------------------------------------------------------------------
  23. CD3DSettingsDlg* g_pD3DSettings = NULL;
  24. DXUTDeviceSettings g_DeviceSettings;
  25.  
  26. CD3DSettingsDlg* DXUTGetSettingsDialog()
  27. {
  28.     // Using an accessor function gives control of the construction order
  29.     static CD3DSettingsDlg dlg;
  30.     return &dlg;
  31. }
  32.  
  33.  
  34. //--------------------------------------------------------------------------------------
  35. CD3DSettingsDlg::CD3DSettingsDlg()
  36. {
  37.     g_pD3DSettings = this;
  38.  
  39.     m_dwWindowWidth = 640;
  40.     m_dwWindowHeight = 480;
  41.  
  42.     CreateControls();
  43. }
  44.  
  45.  
  46. //--------------------------------------------------------------------------------------
  47. CD3DSettingsDlg::~CD3DSettingsDlg()
  48. {
  49.     OnDestroyDevice();
  50. }
  51.  
  52.  
  53. //--------------------------------------------------------------------------------------
  54. void CD3DSettingsDlg::CreateControls()
  55. {
  56.     m_Dialog.EnableKeyboardInput( true );
  57.     m_Dialog.SetFont( 0, L"Arial", 15, FW_NORMAL );
  58.     m_Dialog.SetFont( 1, L"Arial", 28, FW_BOLD );
  59.  
  60.     // Right-justify static controls
  61.     CDXUTElement* pElement = m_Dialog.GetDefaultElement( DXUT_CONTROL_STATIC, 0 );
  62.     pElement->dwTextFormat = DT_VCENTER | DT_RIGHT;
  63.     
  64.     // Title
  65.     CDXUTStatic* pStatic = NULL;
  66.     m_Dialog.AddStatic( DXUTSETTINGSDLG_STATIC, L"Direct3D Settings", 10, 5, 400, 50, false, &pStatic );
  67.     pElement = pStatic->GetElement( 0 );
  68.     pElement->iFont = 1;
  69.     pElement->dwTextFormat = DT_TOP | DT_LEFT;
  70.  
  71.     // DXUTSETTINGSDLG_ADAPTER
  72.     m_Dialog.AddStatic( DXUTSETTINGSDLG_STATIC, L"Display Adapter", 10, 50, 180, 23 );
  73.     m_Dialog.AddComboBox( DXUTSETTINGSDLG_ADAPTER, 200, 50, 300, 23 );
  74.  
  75.     // DXUTSETTINGSDLG_DEVICE_TYPE
  76.     m_Dialog.AddStatic( DXUTSETTINGSDLG_STATIC, L"Render Device", 10, 75, 180, 23 );
  77.     m_Dialog.AddComboBox( DXUTSETTINGSDLG_DEVICE_TYPE, 200, 75, 300, 23 );
  78.  
  79.     // DXUTSETTINGSDLG_WINDOWED, DXUTSETTINGSDLG_FULLSCREEN
  80.     m_Dialog.AddRadioButton( DXUTSETTINGSDLG_WINDOWED, DXUTSETTINGSDLG_WINDOWED_GROUP, L"Windowed", 240, 105, 300, 16 );
  81.     m_Dialog.AddCheckBox( DXUTSETTINGSDLG_DEVICECLIP, L"Clip to device when window spans across multiple monitors", 250, 126, 400, 16 );
  82.     m_Dialog.AddRadioButton( DXUTSETTINGSDLG_FULLSCREEN, DXUTSETTINGSDLG_WINDOWED_GROUP, L"Full Screen", 240, 147, 300, 16 );
  83.  
  84.     // DXUTSETTINGSDLG_ADAPTER_FORMAT
  85.     m_Dialog.AddStatic( DXUTSETTINGSDLG_ADAPTER_FORMAT_LABEL, L"Adapter Format", 10, 180, 180, 23 );
  86.     m_Dialog.AddComboBox( DXUTSETTINGSDLG_ADAPTER_FORMAT, 200, 180, 300, 23 );
  87.  
  88.     // DXUTSETTINGSDLG_RESOLUTION
  89.     m_Dialog.AddStatic( DXUTSETTINGSDLG_RESOLUTION_LABEL, L"Resolution", 10, 205, 180, 23 );
  90.     m_Dialog.AddComboBox( DXUTSETTINGSDLG_RESOLUTION, 200, 205, 300, 23 );
  91.     m_Dialog.GetComboBox( DXUTSETTINGSDLG_RESOLUTION )->SetDropHeight( 106 );
  92.  
  93.     // DXUTSETTINGSDLG_REFRESH_RATE
  94.     m_Dialog.AddStatic( DXUTSETTINGSDLG_REFRESH_RATE_LABEL, L"Refresh Rate", 10, 230, 180, 23 );
  95.     m_Dialog.AddComboBox( DXUTSETTINGSDLG_REFRESH_RATE, 200, 230, 300, 23 );
  96.  
  97.     // DXUTSETTINGSDLG_BACK_BUFFER_FORMAT
  98.     m_Dialog.AddStatic( DXUTSETTINGSDLG_STATIC, L"Back Buffer Format", 10, 265, 180, 23 );
  99.     m_Dialog.AddComboBox( DXUTSETTINGSDLG_BACK_BUFFER_FORMAT, 200, 265, 300, 23 );
  100.  
  101.     // DXUTSETTINGSDLG_DEPTH_STENCIL
  102.     m_Dialog.AddStatic( DXUTSETTINGSDLG_STATIC, L"Depth/Stencil Format", 10, 290, 180, 23 );
  103.     m_Dialog.AddComboBox( DXUTSETTINGSDLG_DEPTH_STENCIL, 200, 290, 300, 23 );
  104.  
  105.     // DXUTSETTINGSDLG_MULTISAMPLE_TYPE
  106.     m_Dialog.AddStatic( DXUTSETTINGSDLG_STATIC, L"Multisample Type", 10, 315, 180, 23 );
  107.     m_Dialog.AddComboBox( DXUTSETTINGSDLG_MULTISAMPLE_TYPE, 200, 315, 300, 23 );
  108.  
  109.     // DXUTSETTINGSDLG_MULTISAMPLE_QUALITY
  110.     m_Dialog.AddStatic( DXUTSETTINGSDLG_STATIC, L"Multisample Quality", 10, 340, 180, 23 );
  111.     m_Dialog.AddComboBox( DXUTSETTINGSDLG_MULTISAMPLE_QUALITY, 200, 340, 300, 23 );
  112.  
  113.      // DXUTSETTINGSDLG_VERTEX_PROCESSING
  114.     m_Dialog.AddStatic( DXUTSETTINGSDLG_STATIC, L"Vertex Processing", 10, 365, 180, 23 );
  115.     m_Dialog.AddComboBox( DXUTSETTINGSDLG_VERTEX_PROCESSING, 200, 365, 300, 23 );
  116.  
  117.      // DXUTSETTINGSDLG_PRESENT_INTERVAL
  118.     m_Dialog.AddStatic( DXUTSETTINGSDLG_STATIC, L"Present Interval", 10, 390, 180, 23 );
  119.     m_Dialog.AddComboBox( DXUTSETTINGSDLG_PRESENT_INTERVAL, 200, 390, 300, 23 );
  120.     
  121.     // DXUTSETTINGSDLG_OK, DXUTSETTINGSDLG_CANCEL
  122.     m_Dialog.AddButton( DXUTSETTINGSDLG_OK, L"OK", 230, 435, 73, 31 );
  123.     m_Dialog.AddButton( DXUTSETTINGSDLG_CANCEL, L"Cancel", 315, 435, 73, 31, 0, true );
  124. }
  125.  
  126.  
  127. //--------------------------------------------------------------------------------------
  128. HRESULT CD3DSettingsDlg::OnCreateDevice( IDirect3DDevice9* pd3dDevice )
  129. {
  130.     if( pd3dDevice == NULL )
  131.         return DXUT_ERR_MSGBOX( L"CD3DSettingsDlg::OnCreatedDevice", E_INVALIDARG );
  132.  
  133.     // Create the fonts/textures 
  134.     m_Dialog.SetCallback( StaticOnEvent );
  135.  
  136.     return S_OK;
  137. }
  138.  
  139.  
  140. //--------------------------------------------------------------------------------------
  141. // Changes the UI defaults to the current device settings
  142. //--------------------------------------------------------------------------------------
  143. HRESULT CD3DSettingsDlg::Refresh()
  144. {
  145.     HRESULT hr = S_OK;
  146.  
  147.     CD3DEnumeration* pD3DEnum = DXUTGetEnumeration();
  148.     g_DeviceSettings = DXUTGetDeviceSettings();
  149.  
  150.     RECT rcClient = DXUTGetWindowClientRect();
  151.     m_dwWindowWidth  = rcClient.right - rcClient.left;
  152.     m_dwWindowHeight = rcClient.bottom - rcClient.top;
  153.  
  154.     // Fill the UI with the current settings
  155.     AddDeviceType( g_DeviceSettings.DeviceType );
  156.     SetWindowed( FALSE != g_DeviceSettings.pp.Windowed );
  157.     SetDeviceClip( 0 != (g_DeviceSettings.pp.Flags & D3DPRESENTFLAG_DEVICECLIP) );
  158.     AddAdapterFormat( g_DeviceSettings.AdapterFormat );
  159.     AddResolution( g_DeviceSettings.pp.BackBufferWidth, g_DeviceSettings.pp.BackBufferHeight );
  160.     AddRefreshRate( g_DeviceSettings.pp.FullScreen_RefreshRateInHz );
  161.     AddBackBufferFormat( g_DeviceSettings.pp.BackBufferFormat );
  162.     AddDepthStencilBufferFormat( g_DeviceSettings.pp.AutoDepthStencilFormat );
  163.     AddMultisampleType( g_DeviceSettings.pp.MultiSampleType );
  164.     AddMultisampleQuality( g_DeviceSettings.pp.MultiSampleQuality );
  165.     
  166.     if( g_DeviceSettings.BehaviorFlags & D3DCREATE_PUREDEVICE )
  167.         AddVertexProcessingType( D3DCREATE_PUREDEVICE );
  168.     else if( g_DeviceSettings.BehaviorFlags & D3DCREATE_HARDWARE_VERTEXPROCESSING )
  169.         AddVertexProcessingType( D3DCREATE_HARDWARE_VERTEXPROCESSING );
  170.     else if( g_DeviceSettings.BehaviorFlags & D3DCREATE_SOFTWARE_VERTEXPROCESSING )
  171.         AddVertexProcessingType( D3DCREATE_SOFTWARE_VERTEXPROCESSING );
  172.     else if( g_DeviceSettings.BehaviorFlags & D3DCREATE_MIXED_VERTEXPROCESSING )
  173.         AddVertexProcessingType( D3DCREATE_MIXED_VERTEXPROCESSING );
  174.  
  175.     AddPresentInterval( g_DeviceSettings.pp.PresentationInterval );
  176.  
  177.  
  178.     CD3DEnumDeviceSettingsCombo* pBestDeviceSettingsCombo = pD3DEnum->GetDeviceSettingsCombo( g_DeviceSettings.AdapterOrdinal, g_DeviceSettings.DeviceType, g_DeviceSettings.AdapterFormat, g_DeviceSettings.pp.BackBufferFormat, (g_DeviceSettings.pp.Windowed != 0) );
  179.     if( NULL == pBestDeviceSettingsCombo )
  180.         return DXUT_ERR_MSGBOX( L"GetDeviceSettingsCombo", E_INVALIDARG );    
  181.  
  182.     // Get the adapters list from CD3DEnumeration object
  183.     CGrowableArray<CD3DEnumAdapterInfo*>* pAdapterInfoList = pD3DEnum->GetAdapterInfoList();
  184.  
  185.     if( pAdapterInfoList->GetSize() == 0 )
  186.         return DXUT_ERR_MSGBOX( L"CD3DSettingsDlg::OnCreatedDevice", DXUTERR_NOCOMPATIBLEDEVICES );
  187.     
  188.     CDXUTComboBox* pAdapterCombo = m_Dialog.GetComboBox( DXUTSETTINGSDLG_ADAPTER );
  189.     pAdapterCombo->RemoveAllItems();
  190.  
  191.     // Add adapters
  192.     for( int iAdapter=0; iAdapter<pAdapterInfoList->GetSize(); iAdapter++ )
  193.     {          
  194.         CD3DEnumAdapterInfo* pAdapterInfo = pAdapterInfoList->GetAt(iAdapter);
  195.         AddAdapter( pAdapterInfo->szUniqueDescription, pAdapterInfo->AdapterOrdinal );
  196.     }
  197.     
  198.     pAdapterCombo->SetSelectedByData( ULongToPtr( g_DeviceSettings.AdapterOrdinal ) );
  199.  
  200.     hr = OnAdapterChanged();
  201.     if( FAILED(hr) )
  202.         return hr;
  203.  
  204.     //m_Dialog.Refresh();
  205.     CDXUTDialog::SetRefreshTime( (float) DXUTGetTime() );
  206.  
  207.     return S_OK;
  208. }
  209.  
  210.  
  211. //--------------------------------------------------------------------------------------
  212. HRESULT CD3DSettingsDlg::OnResetDevice()
  213. {
  214.     const D3DSURFACE_DESC* pDesc = DXUTGetBackBufferSurfaceDesc();
  215.     m_Dialog.SetLocation( 0, 0 );
  216.     m_Dialog.SetSize( pDesc->Width, pDesc->Height );
  217.     m_Dialog.SetBackgroundColors( D3DCOLOR_ARGB(255, 98, 138, 206), 
  218.                                          D3DCOLOR_ARGB(255, 54, 105, 192),
  219.                                          D3DCOLOR_ARGB(255, 54, 105, 192),
  220.                                          D3DCOLOR_ARGB(255, 10,  73, 179) );
  221.     
  222.     return S_OK;
  223. }
  224.  
  225.  
  226. //--------------------------------------------------------------------------------------
  227. HRESULT CD3DSettingsDlg::OnRender( float fElapsedTime )
  228. {
  229.     m_Dialog.OnRender( fElapsedTime );
  230.     return S_OK;
  231. }
  232.  
  233.  
  234. //--------------------------------------------------------------------------------------
  235. LRESULT CD3DSettingsDlg::HandleMessages( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
  236. {
  237.     m_Dialog.MsgProc( hWnd, uMsg, wParam, lParam );
  238.     return 0;
  239. }
  240.  
  241.  
  242. //--------------------------------------------------------------------------------------
  243. HRESULT CD3DSettingsDlg::OnLostDevice()
  244. {
  245.     return S_OK;
  246. }
  247.  
  248.  
  249. //--------------------------------------------------------------------------------------
  250. HRESULT CD3DSettingsDlg::OnDestroyDevice()
  251. {
  252.     m_Dialog.ClearFocus();
  253.     return S_OK;
  254. }
  255.  
  256.  
  257. //--------------------------------------------------------------------------------------
  258. void WINAPI CD3DSettingsDlg::StaticOnEvent( UINT nEvent, int nControlID, 
  259.                                             CDXUTControl* pControl )
  260. {
  261.     if( g_pD3DSettings )
  262.         g_pD3DSettings->OnEvent( nEvent, nControlID, pControl );
  263. }
  264.  
  265.  
  266. //--------------------------------------------------------------------------------------
  267. void CD3DSettingsDlg::OnEvent( UINT nEvent, int nControlID, 
  268.                                CDXUTControl* pControl )
  269. {
  270.     switch( nControlID )
  271.     {
  272.         case DXUTSETTINGSDLG_ADAPTER:               OnAdapterChanged(); break;
  273.         case DXUTSETTINGSDLG_DEVICE_TYPE:           OnDeviceTypeChanged(); break;
  274.         case DXUTSETTINGSDLG_WINDOWED:              OnWindowedFullScreenChanged(); break;
  275.         case DXUTSETTINGSDLG_FULLSCREEN:            OnWindowedFullScreenChanged(); break;
  276.         case DXUTSETTINGSDLG_ADAPTER_FORMAT:        OnAdapterFormatChanged(); break;
  277.         case DXUTSETTINGSDLG_RESOLUTION:            OnResolutionChanged(); break;
  278.         case DXUTSETTINGSDLG_REFRESH_RATE:          OnRefreshRateChanged(); break;
  279.         case DXUTSETTINGSDLG_BACK_BUFFER_FORMAT:    OnBackBufferFormatChanged(); break;
  280.         case DXUTSETTINGSDLG_DEPTH_STENCIL:         OnDepthStencilBufferFormatChanged(); break;
  281.         case DXUTSETTINGSDLG_MULTISAMPLE_TYPE:      OnMultisampleTypeChanged(); break;
  282.         case DXUTSETTINGSDLG_MULTISAMPLE_QUALITY:   OnMultisampleQualityChanged(); break;
  283.         case DXUTSETTINGSDLG_VERTEX_PROCESSING:     OnVertexProcessingChanged(); break;
  284.         case DXUTSETTINGSDLG_PRESENT_INTERVAL:      OnPresentIntervalChanged(); break;
  285.         case DXUTSETTINGSDLG_DEVICECLIP:            OnDeviceClipChanged(); break;
  286.  
  287.         case DXUTSETTINGSDLG_OK:
  288.         {
  289.             if( g_DeviceSettings.pp.Windowed )
  290.             {
  291.                 g_DeviceSettings.pp.FullScreen_RefreshRateInHz = 0;
  292.                 g_DeviceSettings.pp.BackBufferWidth = m_dwWindowWidth;
  293.                 g_DeviceSettings.pp.BackBufferHeight = m_dwWindowHeight;
  294.             }
  295.  
  296.             if( g_DeviceSettings.pp.MultiSampleType != D3DMULTISAMPLE_NONE )
  297.             {
  298.                 g_DeviceSettings.pp.Flags &= ~D3DPRESENTFLAG_LOCKABLE_BACKBUFFER;
  299.             }
  300.  
  301.             DXUTCreateDeviceFromSettings( &g_DeviceSettings );
  302.  
  303.             DXUTSetShowSettingsDialog( false );
  304.             break;
  305.         }
  306.  
  307.         case DXUTSETTINGSDLG_CANCEL:                
  308.         {
  309.             DXUTSetShowSettingsDialog( false ); 
  310.             break;
  311.         }
  312.  
  313.     }
  314. }
  315.  
  316.  
  317. //-------------------------------------------------------------------------------------
  318. HRESULT CD3DSettingsDlg::SetDeviceSettingsFromUI()
  319. {
  320.     CDXUTComboBox* pComboBox;
  321.     CDXUTRadioButton* pRadioButton;
  322.  
  323.     // DXUTSETTINGSDLG_DEVICE_TYPE
  324.     pComboBox = m_Dialog.GetComboBox( DXUTSETTINGSDLG_DEVICE_TYPE );
  325.     g_DeviceSettings.DeviceType = (D3DDEVTYPE) PtrToUlong( pComboBox->GetSelectedData() );
  326.     
  327.     // DXUTSETTINGSDLG_WINDOWED
  328.     pRadioButton = m_Dialog.GetRadioButton( DXUTSETTINGSDLG_WINDOWED );
  329.     g_DeviceSettings.pp.Windowed = pRadioButton->GetChecked();
  330.  
  331.     // DXUTSETTINGSDLG_ADAPTER_FORMAT
  332.     pComboBox = m_Dialog.GetComboBox( DXUTSETTINGSDLG_ADAPTER_FORMAT );
  333.     g_DeviceSettings.AdapterFormat = (D3DFORMAT) PtrToUlong( pComboBox->GetSelectedData() );
  334.     
  335.  
  336.     if( g_DeviceSettings.pp.Windowed )
  337.     {
  338.         g_DeviceSettings.pp.BackBufferFormat = D3DFMT_UNKNOWN;
  339.         g_DeviceSettings.pp.FullScreen_RefreshRateInHz = 0;
  340.     }
  341.     else
  342.     {
  343.         // DXUTSETTINGSDLG_BACK_BUFFER_FORMAT
  344.         pComboBox = m_Dialog.GetComboBox( DXUTSETTINGSDLG_BACK_BUFFER_FORMAT );
  345.         g_DeviceSettings.pp.BackBufferFormat = (D3DFORMAT) PtrToUlong( pComboBox->GetSelectedData() );
  346.     
  347.         // DXUTSETTINGSDLG_RESOLUTION
  348.         pComboBox = m_Dialog.GetComboBox( DXUTSETTINGSDLG_RESOLUTION );
  349.         DWORD dwResolution = PtrToUlong( pComboBox->GetSelectedData() );
  350.         g_DeviceSettings.pp.BackBufferWidth = HIWORD( dwResolution );
  351.         g_DeviceSettings.pp.BackBufferHeight = LOWORD( dwResolution );
  352.         
  353.         // DXUTSETTINGSDLG_REFRESH_RATE
  354.         pComboBox = m_Dialog.GetComboBox( DXUTSETTINGSDLG_REFRESH_RATE );
  355.         g_DeviceSettings.pp.FullScreen_RefreshRateInHz = PtrToUlong( pComboBox->GetSelectedData() );
  356.     }
  357.  
  358.     // DXUTSETTINGSDLG_DEPTH_STENCIL
  359.     pComboBox = m_Dialog.GetComboBox( DXUTSETTINGSDLG_DEPTH_STENCIL );
  360.     g_DeviceSettings.pp.AutoDepthStencilFormat = (D3DFORMAT) PtrToUlong( pComboBox->GetSelectedData() );
  361.     
  362.     return S_OK;
  363. }
  364.  
  365.  
  366. //-------------------------------------------------------------------------------------
  367. CD3DEnumAdapterInfo* CD3DSettingsDlg::GetCurrentAdapterInfo()
  368. {
  369.     CD3DEnumeration* pD3DEnum = DXUTGetEnumeration();
  370.     return pD3DEnum->GetAdapterInfo( g_DeviceSettings.AdapterOrdinal );
  371. }
  372.  
  373.  
  374. //-------------------------------------------------------------------------------------
  375. CD3DEnumDeviceInfo* CD3DSettingsDlg::GetCurrentDeviceInfo()
  376. {
  377.     CD3DEnumeration* pD3DEnum = DXUTGetEnumeration();
  378.     return pD3DEnum->GetDeviceInfo( g_DeviceSettings.AdapterOrdinal,
  379.                                       g_DeviceSettings.DeviceType );
  380. }
  381.  
  382.  
  383. //-------------------------------------------------------------------------------------
  384. CD3DEnumDeviceSettingsCombo* CD3DSettingsDlg::GetCurrentDeviceSettingsCombo()
  385. {
  386.     CD3DEnumeration* pD3DEnum = DXUTGetEnumeration();
  387.     return pD3DEnum->GetDeviceSettingsCombo( g_DeviceSettings.AdapterOrdinal,
  388.                                              g_DeviceSettings.DeviceType,
  389.                                              g_DeviceSettings.AdapterFormat,
  390.                                              g_DeviceSettings.pp.BackBufferFormat,
  391.                                              (g_DeviceSettings.pp.Windowed == TRUE) );
  392. }
  393.  
  394.  
  395. //-------------------------------------------------------------------------------------
  396. HRESULT CD3DSettingsDlg::OnAdapterChanged()
  397. {
  398.     HRESULT hr = S_OK;
  399.  
  400.     // Store the adapter index
  401.     g_DeviceSettings.AdapterOrdinal = GetSelectedAdapter();
  402.     
  403.     // DXUTSETTINGSDLG_DEVICE_TYPE
  404.     CDXUTComboBox* pDeviceTypeComboBox = m_Dialog.GetComboBox( DXUTSETTINGSDLG_DEVICE_TYPE );
  405.     pDeviceTypeComboBox->RemoveAllItems();
  406.  
  407.     CD3DEnumAdapterInfo* pAdapterInfo = GetCurrentAdapterInfo();
  408.     if( pAdapterInfo == NULL )
  409.         return E_FAIL;
  410.  
  411.     for( int iDeviceInfo=0; iDeviceInfo < pAdapterInfo->deviceInfoList.GetSize(); iDeviceInfo++ )
  412.     {
  413.         CD3DEnumDeviceInfo* pDeviceInfo = pAdapterInfo->deviceInfoList.GetAt(iDeviceInfo);
  414.         AddDeviceType( pDeviceInfo->DeviceType );
  415.     }
  416.  
  417.     pDeviceTypeComboBox->SetSelectedByData( ULongToPtr(g_DeviceSettings.DeviceType) );
  418.  
  419.     hr = OnDeviceTypeChanged();
  420.     if( FAILED(hr) )
  421.         return hr;
  422.  
  423.     return S_OK; 
  424. }
  425.  
  426.  
  427.  
  428. //-------------------------------------------------------------------------------------
  429. HRESULT CD3DSettingsDlg::OnDeviceTypeChanged()
  430. {
  431.     HRESULT hr = S_OK;
  432.     
  433.     g_DeviceSettings.DeviceType = GetSelectedDeviceType();
  434.    
  435.     // Update windowed/full screen radio buttons
  436.     bool bHasWindowedDeviceCombo = false;
  437.     bool bHasFullScreenDeviceCombo = false;
  438.  
  439.     CD3DEnumDeviceInfo* pDeviceInfo = GetCurrentDeviceInfo();
  440.     if( pDeviceInfo == NULL )
  441.         return E_FAIL;
  442.             
  443.     for( int idc = 0; idc < pDeviceInfo->deviceSettingsComboList.GetSize(); idc++ )
  444.     {
  445.         CD3DEnumDeviceSettingsCombo* pDeviceSettingsCombo = pDeviceInfo->deviceSettingsComboList.GetAt( idc );
  446.  
  447.         if( pDeviceSettingsCombo->Windowed )
  448.             bHasWindowedDeviceCombo = true;
  449.         else
  450.             bHasFullScreenDeviceCombo = true;
  451.     }
  452.  
  453.     // DXUTSETTINGSDLG_WINDOWED, DXUTSETTINGSDLG_FULLSCREEN
  454.     m_Dialog.SetControlEnabled( DXUTSETTINGSDLG_WINDOWED, bHasWindowedDeviceCombo );
  455.     m_Dialog.SetControlEnabled( DXUTSETTINGSDLG_FULLSCREEN, bHasFullScreenDeviceCombo );
  456.  
  457.     SetWindowed( g_DeviceSettings.pp.Windowed && bHasWindowedDeviceCombo );
  458.  
  459.     hr = OnWindowedFullScreenChanged();
  460.     if( FAILED(hr) )
  461.         return hr;
  462.  
  463.     return S_OK;
  464. }
  465.  
  466.  
  467.  
  468. //-------------------------------------------------------------------------------------
  469. HRESULT CD3DSettingsDlg::OnWindowedFullScreenChanged()
  470. {
  471.     HRESULT hr = S_OK;
  472.  
  473.     bool bWindowed = IsWindowed();
  474.     g_DeviceSettings.pp.Windowed = bWindowed;
  475.  
  476.     m_Dialog.SetControlEnabled( DXUTSETTINGSDLG_ADAPTER_FORMAT_LABEL, !bWindowed );
  477.     m_Dialog.SetControlEnabled( DXUTSETTINGSDLG_RESOLUTION_LABEL, !bWindowed );
  478.     m_Dialog.SetControlEnabled( DXUTSETTINGSDLG_REFRESH_RATE_LABEL, !bWindowed );
  479.  
  480.     m_Dialog.SetControlEnabled( DXUTSETTINGSDLG_ADAPTER_FORMAT, !bWindowed );
  481.     m_Dialog.SetControlEnabled( DXUTSETTINGSDLG_RESOLUTION, !bWindowed );
  482.     m_Dialog.SetControlEnabled( DXUTSETTINGSDLG_REFRESH_RATE, !bWindowed );
  483.     m_Dialog.SetControlEnabled( DXUTSETTINGSDLG_DEVICECLIP, bWindowed );
  484.  
  485.     bool bDeviceClip = ( 0x0 != (g_DeviceSettings.pp.Flags & D3DPRESENTFLAG_DEVICECLIP) );
  486.  
  487.     // If windowed, get the appropriate adapter format from Direct3D
  488.     if( g_DeviceSettings.pp.Windowed )
  489.     {
  490.         IDirect3D9* pD3D = DXUTGetD3DObject();
  491.         if( pD3D == NULL )
  492.             return DXTRACE_ERR( L"DXUTGetD3DObject", E_FAIL );
  493.  
  494.         D3DDISPLAYMODE mode;
  495.         hr = pD3D->GetAdapterDisplayMode( g_DeviceSettings.AdapterOrdinal, &mode );
  496.         if( FAILED(hr) )
  497.             return DXTRACE_ERR( L"GetAdapterDisplayMode", hr );
  498.  
  499.         g_DeviceSettings.AdapterFormat = mode.Format;
  500.         g_DeviceSettings.pp.BackBufferWidth = mode.Width;
  501.         g_DeviceSettings.pp.BackBufferHeight = mode.Height;
  502.         g_DeviceSettings.pp.FullScreen_RefreshRateInHz = mode.RefreshRate;
  503.     }
  504.  
  505.     const D3DFORMAT adapterFormat = g_DeviceSettings.AdapterFormat;
  506.     const DWORD dwWidth = g_DeviceSettings.pp.BackBufferWidth;
  507.     const DWORD dwHeight = g_DeviceSettings.pp.BackBufferHeight;
  508.     const DWORD dwRefreshRate = g_DeviceSettings.pp.FullScreen_RefreshRateInHz;
  509.  
  510.     // DXUTSETTINGSDLG_DEVICECLIP
  511.     SetDeviceClip( bDeviceClip );
  512.     
  513.     // DXUTSETTINGSDLG_ADAPTER_FORMAT
  514.     CDXUTComboBox* pAdapterFormatComboBox = m_Dialog.GetComboBox( DXUTSETTINGSDLG_ADAPTER_FORMAT );
  515.     pAdapterFormatComboBox->RemoveAllItems();
  516.  
  517.     CD3DEnumDeviceInfo* pDeviceInfo = GetCurrentDeviceInfo();
  518.     if( pDeviceInfo == NULL )
  519.         return E_FAIL;
  520.  
  521.     if( bWindowed )
  522.     {
  523.         AddAdapterFormat( adapterFormat );
  524.     }
  525.     else
  526.     {
  527.         for( int iSettingsCombo=0; iSettingsCombo < pDeviceInfo->deviceSettingsComboList.GetSize(); iSettingsCombo++ )
  528.         {
  529.             CD3DEnumDeviceSettingsCombo* pSettingsCombo = pDeviceInfo->deviceSettingsComboList.GetAt(iSettingsCombo);
  530.             AddAdapterFormat( pSettingsCombo->AdapterFormat );
  531.         }    
  532.     }
  533.  
  534.     pAdapterFormatComboBox->SetSelectedByData( ULongToPtr(adapterFormat) );
  535.  
  536.     hr = OnAdapterFormatChanged();
  537.     if( FAILED(hr) )
  538.         return hr;
  539.  
  540.     // DXUTSETTINGSDLG_RESOLUTION
  541.     CDXUTComboBox* pResolutionComboBox = m_Dialog.GetComboBox( DXUTSETTINGSDLG_RESOLUTION );
  542.     
  543.     if( bWindowed )
  544.     {
  545.         pResolutionComboBox->RemoveAllItems();
  546.         AddResolution( dwWidth, dwHeight );
  547.     }
  548.  
  549.     pResolutionComboBox->SetSelectedByData( ULongToPtr( MAKELONG(dwWidth, dwHeight) ) );
  550.     
  551.     hr = OnResolutionChanged();
  552.     if( FAILED(hr) )
  553.         return hr;
  554.  
  555.     // DXUTSETTINGSDLG_REFRESH_RATE
  556.     CDXUTComboBox* pRefreshRateComboBox = m_Dialog.GetComboBox( DXUTSETTINGSDLG_REFRESH_RATE );
  557.     
  558.     if( bWindowed )
  559.     {
  560.         pRefreshRateComboBox->RemoveAllItems();
  561.         AddRefreshRate( dwRefreshRate );
  562.     }
  563.     
  564.     pRefreshRateComboBox->SetSelectedByData( ULongToPtr(dwRefreshRate) ); 
  565.  
  566.     hr = OnRefreshRateChanged();
  567.     if( FAILED(hr) )
  568.         return hr;
  569.  
  570.     return S_OK;
  571. }
  572.  
  573.  
  574. //-------------------------------------------------------------------------------------
  575. HRESULT CD3DSettingsDlg::OnAdapterFormatChanged()
  576.     HRESULT hr = S_OK;
  577.  
  578.     // DXUTSETTINGSDLG_ADAPTER_FORMAT
  579.     D3DFORMAT adapterFormat = GetSelectedAdapterFormat();
  580.     g_DeviceSettings.AdapterFormat = adapterFormat;
  581.  
  582.     // DXUTSETTINGSDLG_RESOLUTION
  583.     CDXUTComboBox* pResolutionComboBox = m_Dialog.GetComboBox( DXUTSETTINGSDLG_RESOLUTION );
  584.     pResolutionComboBox->RemoveAllItems();
  585.  
  586.     CD3DEnumAdapterInfo* pAdapterInfo = GetCurrentAdapterInfo();
  587.     if( pAdapterInfo == NULL )
  588.         return E_FAIL;
  589.  
  590.     for( int idm = 0; idm < pAdapterInfo->displayModeList.GetSize(); idm++ )
  591.     {
  592.         D3DDISPLAYMODE DisplayMode = pAdapterInfo->displayModeList.GetAt( idm );
  593.  
  594.         if( DisplayMode.Format == adapterFormat )
  595.             AddResolution( DisplayMode.Width, DisplayMode.Height );    
  596.     }
  597.  
  598.     const DWORD dwCurResolution = MAKELONG( g_DeviceSettings.pp.BackBufferWidth, 
  599.                                             g_DeviceSettings.pp.BackBufferHeight );
  600.  
  601.     pResolutionComboBox->SetSelectedByData( ULongToPtr(dwCurResolution) );
  602.  
  603.     hr = OnResolutionChanged();
  604.     if( FAILED(hr) )
  605.         return hr;
  606.  
  607.     // DXUTSETTINGSDLG_BACK_BUFFER_FORMAT
  608.     CDXUTComboBox* pBackBufferFormatComboBox = m_Dialog.GetComboBox( DXUTSETTINGSDLG_BACK_BUFFER_FORMAT );
  609.     pBackBufferFormatComboBox->RemoveAllItems();
  610.  
  611.     CD3DEnumDeviceInfo* pDeviceInfo = GetCurrentDeviceInfo();
  612.     if( pDeviceInfo == NULL )
  613.         return E_FAIL;
  614.  
  615.     const BOOL bWindowed = IsWindowed();
  616.     bool bHasWindowedBackBuffer = false;
  617.  
  618.     for( int idc = 0; idc < pDeviceInfo->deviceSettingsComboList.GetSize(); idc++ )
  619.     {
  620.         CD3DEnumDeviceSettingsCombo* pDeviceCombo = pDeviceInfo->deviceSettingsComboList.GetAt( idc );
  621.         if( pDeviceCombo->Windowed == bWindowed &&
  622.             pDeviceCombo->AdapterFormat == g_DeviceSettings.AdapterFormat )
  623.         {
  624.             AddBackBufferFormat( pDeviceCombo->BackBufferFormat );
  625.             bHasWindowedBackBuffer = true;
  626.         }
  627.     }
  628.  
  629.     pBackBufferFormatComboBox->SetSelectedByData( ULongToPtr(g_DeviceSettings.pp.BackBufferFormat) );
  630.  
  631.     hr = OnBackBufferFormatChanged();
  632.     if( FAILED(hr) )
  633.         return hr;
  634.  
  635.     if( !bHasWindowedBackBuffer )
  636.     {
  637.         m_Dialog.SetControlEnabled( DXUTSETTINGSDLG_WINDOWED, false );
  638.  
  639.         if( g_DeviceSettings.pp.Windowed )
  640.         {
  641.             SetWindowed( false );
  642.  
  643.             hr = OnWindowedFullScreenChanged();
  644.             if( FAILED(hr) )
  645.                 return hr;
  646.         }
  647.     }
  648.  
  649.     return S_OK;
  650. }
  651.  
  652.  
  653. //-------------------------------------------------------------------------------------
  654. HRESULT CD3DSettingsDlg::OnResolutionChanged()
  655. {
  656.     HRESULT hr = S_OK;
  657.  
  658.     CD3DEnumAdapterInfo* pAdapterInfo = GetCurrentAdapterInfo();
  659.     if( pAdapterInfo == NULL )
  660.         return E_FAIL;
  661.  
  662.     // Set resolution
  663.     DWORD dwWidth, dwHeight;
  664.     GetSelectedResolution( &dwWidth, &dwHeight );
  665.     g_DeviceSettings.pp.BackBufferWidth = dwWidth;
  666.     g_DeviceSettings.pp.BackBufferHeight = dwHeight;
  667.  
  668.     DWORD dwRefreshRate = g_DeviceSettings.pp.FullScreen_RefreshRateInHz;
  669.  
  670.     // Update the refresh rate list
  671.     CDXUTComboBox* pRefreshRateComboBox = m_Dialog.GetComboBox( DXUTSETTINGSDLG_REFRESH_RATE );
  672.     pRefreshRateComboBox->RemoveAllItems();
  673.  
  674.     D3DFORMAT adapterFormat = g_DeviceSettings.AdapterFormat;
  675.     for( int idm = 0; idm < pAdapterInfo->displayModeList.GetSize(); idm++ )
  676.     {
  677.         D3DDISPLAYMODE displayMode = pAdapterInfo->displayModeList.GetAt( idm );
  678.  
  679.         if( displayMode.Format == adapterFormat &&
  680.             displayMode.Width == dwWidth &&
  681.             displayMode.Height == dwHeight )
  682.         {
  683.             AddRefreshRate( displayMode.RefreshRate );
  684.         }
  685.     }
  686.  
  687.     pRefreshRateComboBox->SetSelectedByData( ULongToPtr(dwRefreshRate) );
  688.  
  689.     hr = OnRefreshRateChanged();
  690.     if( FAILED(hr) )
  691.         return hr;
  692.  
  693.     return S_OK;
  694. }
  695.  
  696.  
  697. //-------------------------------------------------------------------------------------
  698. HRESULT CD3DSettingsDlg::OnRefreshRateChanged()
  699. {
  700.     // Set refresh rate
  701.     g_DeviceSettings.pp.FullScreen_RefreshRateInHz = GetSelectedRefreshRate();
  702.  
  703.     return S_OK;
  704. }
  705.  
  706.  
  707. //-------------------------------------------------------------------------------------
  708. HRESULT CD3DSettingsDlg::OnBackBufferFormatChanged()
  709. {
  710.     HRESULT hr = S_OK;
  711.  
  712.     g_DeviceSettings.pp.BackBufferFormat = GetSelectedBackBufferFormat();
  713.     
  714.     D3DFORMAT adapterFormat = g_DeviceSettings.AdapterFormat;
  715.     D3DFORMAT backBufferFormat = g_DeviceSettings.pp.BackBufferFormat;
  716.  
  717.     CD3DEnumDeviceInfo* pDeviceInfo = GetCurrentDeviceInfo();
  718.     if( pDeviceInfo == NULL )
  719.         return E_FAIL;
  720.  
  721.     bool bAllowSoftwareVP, bAllowHardwareVP, bAllowPureHardwareVP, bAllowMixedVP;
  722.     DXUTGetEnumeration()->GetPossibleVertexProcessingList( &bAllowSoftwareVP, &bAllowHardwareVP, 
  723.                                                            &bAllowPureHardwareVP, &bAllowMixedVP );
  724.     
  725.     for( int idc=0; idc < pDeviceInfo->deviceSettingsComboList.GetSize(); idc++ )
  726.     {
  727.         CD3DEnumDeviceSettingsCombo* pDeviceCombo = pDeviceInfo->deviceSettingsComboList.GetAt( idc );
  728.  
  729.         if( pDeviceCombo->Windowed == (g_DeviceSettings.pp.Windowed == TRUE) &&
  730.             pDeviceCombo->AdapterFormat == adapterFormat &&
  731.             pDeviceCombo->BackBufferFormat == backBufferFormat )
  732.         {
  733.             CDXUTComboBox* pDepthStencilComboBox = m_Dialog.GetComboBox( DXUTSETTINGSDLG_DEPTH_STENCIL );
  734.             pDepthStencilComboBox->RemoveAllItems();
  735.             pDepthStencilComboBox->SetEnabled( (g_DeviceSettings.pp.EnableAutoDepthStencil == TRUE) ); 
  736.  
  737.             if( g_DeviceSettings.pp.EnableAutoDepthStencil )
  738.             {
  739.                 for( int ifmt=0; ifmt < pDeviceCombo->depthStencilFormatList.GetSize(); ifmt++ )
  740.                 {
  741.                     D3DFORMAT fmt = pDeviceCombo->depthStencilFormatList.GetAt( ifmt );
  742.  
  743.                     AddDepthStencilBufferFormat( fmt );
  744.                 }
  745.  
  746.                 pDepthStencilComboBox->SetSelectedByData( ULongToPtr(g_DeviceSettings.pp.AutoDepthStencilFormat) );
  747.             }
  748.             else
  749.             {
  750.                 if( !pDepthStencilComboBox->ContainsItem( L"(not used)" ) )
  751.                     pDepthStencilComboBox->AddItem( L"(not used)", NULL );
  752.             }
  753.  
  754.             hr = OnDepthStencilBufferFormatChanged();
  755.             if( FAILED(hr) )
  756.                 return hr;
  757.  
  758.             CDXUTComboBox* pVertexProcessingComboBox = m_Dialog.GetComboBox( DXUTSETTINGSDLG_VERTEX_PROCESSING );
  759.             pVertexProcessingComboBox->RemoveAllItems();
  760.  
  761.             // Add valid vertex processing types
  762.             if( bAllowSoftwareVP )
  763.                 AddVertexProcessingType( D3DCREATE_SOFTWARE_VERTEXPROCESSING );
  764.  
  765.             if( bAllowHardwareVP && pDeviceInfo->Caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT )
  766.                 AddVertexProcessingType( D3DCREATE_HARDWARE_VERTEXPROCESSING );
  767.  
  768.             if( bAllowPureHardwareVP && pDeviceInfo->Caps.DevCaps & D3DDEVCAPS_PUREDEVICE )
  769.                 AddVertexProcessingType( D3DCREATE_PUREDEVICE );
  770.  
  771.             if( bAllowMixedVP && pDeviceInfo->Caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT )
  772.                 AddVertexProcessingType( D3DCREATE_MIXED_VERTEXPROCESSING );
  773.  
  774.             if( g_DeviceSettings.BehaviorFlags & D3DCREATE_PUREDEVICE )
  775.                 pVertexProcessingComboBox->SetSelectedByData( ULongToPtr(D3DCREATE_PUREDEVICE) );
  776.             else if( g_DeviceSettings.BehaviorFlags & D3DCREATE_SOFTWARE_VERTEXPROCESSING )
  777.                 pVertexProcessingComboBox->SetSelectedByData( ULongToPtr(D3DCREATE_SOFTWARE_VERTEXPROCESSING) );
  778.             else if( g_DeviceSettings.BehaviorFlags & D3DCREATE_HARDWARE_VERTEXPROCESSING )
  779.                 pVertexProcessingComboBox->SetSelectedByData( ULongToPtr(D3DCREATE_HARDWARE_VERTEXPROCESSING) );
  780.             else if( g_DeviceSettings.BehaviorFlags & D3DCREATE_MIXED_VERTEXPROCESSING )
  781.                 pVertexProcessingComboBox->SetSelectedByData( ULongToPtr(D3DCREATE_MIXED_VERTEXPROCESSING) );
  782.  
  783.             hr = OnVertexProcessingChanged();
  784.             if( FAILED(hr) )
  785.                 return hr;
  786.  
  787.             CDXUTComboBox* pPresentIntervalComboBox = m_Dialog.GetComboBox( DXUTSETTINGSDLG_PRESENT_INTERVAL );
  788.             pPresentIntervalComboBox->RemoveAllItems();
  789.  
  790.             for( int ipi=0; ipi < pDeviceCombo->presentIntervalList.GetSize(); ipi++ )
  791.             {
  792.                 UINT presentInterval = pDeviceCombo->presentIntervalList.GetAt( ipi );
  793.                 
  794.                 AddPresentInterval( presentInterval );
  795.             }
  796.  
  797.             pPresentIntervalComboBox->SetSelectedByData( ULongToPtr( g_DeviceSettings.pp.PresentationInterval ) );
  798.         
  799.             hr = OnPresentIntervalChanged();
  800.             if( FAILED(hr) )
  801.                 return hr;
  802.         }
  803.     }
  804.  
  805.     return S_OK;
  806. }
  807.  
  808.  
  809. //-------------------------------------------------------------------------------------
  810. HRESULT CD3DSettingsDlg::OnDepthStencilBufferFormatChanged()
  811. {
  812.     HRESULT hr = S_OK;
  813.  
  814.     D3DFORMAT depthStencilBufferFormat = GetSelectedDepthStencilBufferFormat();
  815.  
  816.     if( g_DeviceSettings.pp.EnableAutoDepthStencil )
  817.         g_DeviceSettings.pp.AutoDepthStencilFormat = depthStencilBufferFormat;
  818.  
  819.     CD3DEnumDeviceSettingsCombo* pDeviceSettingsCombo = GetCurrentDeviceSettingsCombo();
  820.     if( pDeviceSettingsCombo == NULL )
  821.         return E_FAIL;
  822.     
  823.     CDXUTComboBox* pMultisampleTypeCombo = m_Dialog.GetComboBox( DXUTSETTINGSDLG_MULTISAMPLE_TYPE );
  824.     pMultisampleTypeCombo->RemoveAllItems();
  825.  
  826.     for( int ims=0; ims < pDeviceSettingsCombo->multiSampleTypeList.GetSize(); ims++ )
  827.     {
  828.         D3DMULTISAMPLE_TYPE msType = pDeviceSettingsCombo->multiSampleTypeList.GetAt( ims );
  829.  
  830.         bool bConflictFound = false;
  831.         for( int iConf = 0; iConf < pDeviceSettingsCombo->DSMSConflictList.GetSize(); iConf++ )
  832.         {
  833.             CD3DEnumDSMSConflict DSMSConf = pDeviceSettingsCombo->DSMSConflictList.GetAt( iConf );
  834.             if( DSMSConf.DSFormat == depthStencilBufferFormat &&
  835.                 DSMSConf.MSType == msType )
  836.             {
  837.                 bConflictFound = true;
  838.                 break;
  839.             }
  840.         }
  841.  
  842.         if( !bConflictFound )
  843.             AddMultisampleType( msType );
  844.     }
  845.  
  846.     CDXUTComboBox* pMultisampleQualityCombo = m_Dialog.GetComboBox( DXUTSETTINGSDLG_MULTISAMPLE_TYPE );
  847.     pMultisampleQualityCombo->SetSelectedByData( ULongToPtr(g_DeviceSettings.pp.MultiSampleType) );
  848.  
  849.     hr = OnMultisampleTypeChanged();
  850.     if( FAILED(hr) )
  851.         return hr;
  852.  
  853.     return S_OK;
  854. }
  855.  
  856.  
  857. //-------------------------------------------------------------------------------------
  858. HRESULT CD3DSettingsDlg::OnMultisampleTypeChanged()
  859. {
  860.     HRESULT hr = S_OK;
  861.  
  862.     D3DMULTISAMPLE_TYPE multisampleType = GetSelectedMultisampleType();
  863.     g_DeviceSettings.pp.MultiSampleType = multisampleType;
  864.  
  865.     CD3DEnumDeviceSettingsCombo* pDeviceSettingsCombo = GetCurrentDeviceSettingsCombo();
  866.     if( pDeviceSettingsCombo == NULL )
  867.         return E_FAIL;
  868.  
  869.     DWORD dwMaxQuality = 0;
  870.     for( int iType = 0; iType < pDeviceSettingsCombo->multiSampleTypeList.GetSize(); iType++ )
  871.     {
  872.         D3DMULTISAMPLE_TYPE msType = pDeviceSettingsCombo->multiSampleTypeList.GetAt( iType );
  873.         if( msType == multisampleType )
  874.         {
  875.             dwMaxQuality = pDeviceSettingsCombo->multiSampleQualityList.GetAt( iType );
  876.             break;
  877.         }
  878.     }
  879.    
  880.     // DXUTSETTINGSDLG_MULTISAMPLE_QUALITY
  881.     CDXUTComboBox* pMultisampleQualityCombo = m_Dialog.GetComboBox( DXUTSETTINGSDLG_MULTISAMPLE_QUALITY );
  882.     pMultisampleQualityCombo->RemoveAllItems();
  883.  
  884.     for( UINT iQuality = 0; iQuality < dwMaxQuality; iQuality++ )
  885.     {
  886.         AddMultisampleQuality( iQuality );
  887.     }
  888.  
  889.     pMultisampleQualityCombo->SetSelectedByData( ULongToPtr(g_DeviceSettings.pp.MultiSampleQuality) );
  890.  
  891.     hr = OnMultisampleQualityChanged();
  892.     if( FAILED(hr) )
  893.         return hr;
  894.  
  895.     return S_OK;
  896. }
  897.  
  898.  
  899. //-------------------------------------------------------------------------------------
  900. HRESULT CD3DSettingsDlg::OnMultisampleQualityChanged()
  901. {
  902.     g_DeviceSettings.pp.MultiSampleQuality = GetSelectedMultisampleQuality();
  903.  
  904.     return S_OK;
  905. }
  906.  
  907.  
  908. //-------------------------------------------------------------------------------------
  909. HRESULT CD3DSettingsDlg::OnVertexProcessingChanged()
  910. {
  911.     DWORD dwBehavior = g_DeviceSettings.BehaviorFlags;
  912.  
  913.     // Clear vertex processing flags
  914.     dwBehavior &= ~D3DCREATE_HARDWARE_VERTEXPROCESSING;
  915.     dwBehavior &= ~D3DCREATE_SOFTWARE_VERTEXPROCESSING;
  916.     dwBehavior &= ~D3DCREATE_MIXED_VERTEXPROCESSING;
  917.     dwBehavior &= ~D3DCREATE_PUREDEVICE;
  918.  
  919.     // Determine new flags
  920.     DWORD dwNewFlags = GetSelectedVertexProcessingType();
  921.     if( dwNewFlags & D3DCREATE_PUREDEVICE )
  922.         dwNewFlags |= D3DCREATE_HARDWARE_VERTEXPROCESSING;
  923.  
  924.     // Make changes
  925.     g_DeviceSettings.BehaviorFlags = dwBehavior | dwNewFlags;
  926.  
  927.     return S_OK;
  928. }
  929.  
  930.  
  931. //-------------------------------------------------------------------------------------
  932. HRESULT CD3DSettingsDlg::OnPresentIntervalChanged()
  933. {
  934.     g_DeviceSettings.pp.PresentationInterval = GetSelectedPresentInterval();
  935.  
  936.     return S_OK;
  937. }
  938.  
  939.  
  940. //-------------------------------------------------------------------------------------
  941. HRESULT CD3DSettingsDlg::OnDeviceClipChanged()
  942. {
  943.     if( IsDeviceClip() )
  944.         g_DeviceSettings.pp.Flags |= D3DPRESENTFLAG_DEVICECLIP;
  945.     else
  946.         g_DeviceSettings.pp.Flags &= ~D3DPRESENTFLAG_DEVICECLIP;
  947.  
  948.     return S_OK;
  949. }
  950.  
  951.  
  952. //-------------------------------------------------------------------------------------
  953. void CD3DSettingsDlg::AddAdapter( const WCHAR* strDescription, UINT iAdapter )
  954. {
  955.     CDXUTComboBox* pComboBox = m_Dialog.GetComboBox( DXUTSETTINGSDLG_ADAPTER );
  956.  
  957.     if( !pComboBox->ContainsItem( strDescription ) )
  958.         pComboBox->AddItem( strDescription, ULongToPtr(iAdapter) );
  959. }
  960.  
  961.  
  962. //-------------------------------------------------------------------------------------
  963. UINT CD3DSettingsDlg::GetSelectedAdapter()
  964. {
  965.     CDXUTComboBox* pComboBox = m_Dialog.GetComboBox( DXUTSETTINGSDLG_ADAPTER );
  966.  
  967.     return PtrToUlong( pComboBox->GetSelectedData() );  
  968. }
  969.  
  970.  
  971. //-------------------------------------------------------------------------------------
  972. void CD3DSettingsDlg::AddDeviceType( D3DDEVTYPE devType )
  973. {
  974.     CDXUTComboBox* pComboBox = m_Dialog.GetComboBox( DXUTSETTINGSDLG_DEVICE_TYPE );
  975.  
  976.     if( !pComboBox->ContainsItem( DXUTD3DDeviceTypeToString(devType) ) )
  977.         pComboBox->AddItem( DXUTD3DDeviceTypeToString(devType), ULongToPtr(devType) );
  978. }
  979.  
  980.  
  981. //-------------------------------------------------------------------------------------
  982. D3DDEVTYPE CD3DSettingsDlg::GetSelectedDeviceType()
  983. {
  984.     CDXUTComboBox* pComboBox = m_Dialog.GetComboBox( DXUTSETTINGSDLG_DEVICE_TYPE );
  985.  
  986.     return (D3DDEVTYPE) PtrToUlong( pComboBox->GetSelectedData() );
  987. }
  988.  
  989.  
  990. //-------------------------------------------------------------------------------------
  991. void CD3DSettingsDlg::SetWindowed( bool bWindowed )
  992. {
  993.     CDXUTRadioButton* pRadioButton = m_Dialog.GetRadioButton( DXUTSETTINGSDLG_WINDOWED );
  994.     pRadioButton->SetChecked( bWindowed );
  995.  
  996.     pRadioButton = m_Dialog.GetRadioButton( DXUTSETTINGSDLG_FULLSCREEN );
  997.     pRadioButton->SetChecked( !bWindowed );
  998. }
  999.  
  1000.  
  1001. //-------------------------------------------------------------------------------------
  1002. bool CD3DSettingsDlg::IsWindowed()
  1003. {
  1004.     CDXUTRadioButton* pRadioButton = m_Dialog.GetRadioButton( DXUTSETTINGSDLG_WINDOWED );
  1005.     return pRadioButton->GetChecked();
  1006. }
  1007.  
  1008.  
  1009. //-------------------------------------------------------------------------------------
  1010. void CD3DSettingsDlg::AddAdapterFormat( D3DFORMAT format )
  1011. {
  1012.     CDXUTComboBox* pComboBox = m_Dialog.GetComboBox( DXUTSETTINGSDLG_ADAPTER_FORMAT );
  1013.     
  1014.     if( !pComboBox->ContainsItem( DXUTD3DFormatToString(format, TRUE) ) )
  1015.         pComboBox->AddItem( DXUTD3DFormatToString(format, TRUE), ULongToPtr( format ) );
  1016. }
  1017.  
  1018.  
  1019. //-------------------------------------------------------------------------------------
  1020. D3DFORMAT CD3DSettingsDlg::GetSelectedAdapterFormat()
  1021. {
  1022.     CDXUTComboBox* pComboBox = m_Dialog.GetComboBox( DXUTSETTINGSDLG_ADAPTER_FORMAT );
  1023.   
  1024.     return (D3DFORMAT) PtrToUlong( pComboBox->GetSelectedData() ); 
  1025. }
  1026.  
  1027.  
  1028. //-------------------------------------------------------------------------------------
  1029. void CD3DSettingsDlg::AddResolution( DWORD dwWidth, DWORD dwHeight )
  1030. {
  1031.     CDXUTComboBox* pComboBox = m_Dialog.GetComboBox( DXUTSETTINGSDLG_RESOLUTION );
  1032.   
  1033.     DWORD dwResolutionData;
  1034.     WCHAR strResolution[50];
  1035.     dwResolutionData = MAKELONG( dwWidth, dwHeight );
  1036.     _snwprintf( strResolution, 50, L"%d by %d", dwWidth, dwHeight );
  1037.     strResolution[49] = 0;
  1038.  
  1039.     if( !pComboBox->ContainsItem( strResolution ) )
  1040.         pComboBox->AddItem( strResolution, ULongToPtr( dwResolutionData ) );
  1041. }
  1042.  
  1043.  
  1044. //-------------------------------------------------------------------------------------
  1045. void CD3DSettingsDlg::GetSelectedResolution( DWORD* pdwWidth, DWORD* pdwHeight )
  1046. {
  1047.     CDXUTComboBox* pComboBox = m_Dialog.GetComboBox( DXUTSETTINGSDLG_RESOLUTION );
  1048.  
  1049.     DWORD dwResolution = PtrToUlong( pComboBox->GetSelectedData() );
  1050.  
  1051.     *pdwWidth = LOWORD( dwResolution );
  1052.     *pdwHeight = HIWORD( dwResolution );
  1053. }
  1054.  
  1055.  
  1056. //-------------------------------------------------------------------------------------
  1057. void CD3DSettingsDlg::AddRefreshRate( DWORD dwRate )
  1058. {
  1059.     CDXUTComboBox* pComboBox = m_Dialog.GetComboBox( DXUTSETTINGSDLG_REFRESH_RATE );
  1060.         
  1061.     WCHAR strRefreshRate[50];
  1062.  
  1063.     if( dwRate == 0 )
  1064.         wcscpy( strRefreshRate, L"Default Rate" );
  1065.     else
  1066.         _snwprintf( strRefreshRate, 50, L"%d Hz", dwRate );
  1067.  
  1068.     strRefreshRate[49] = 0;
  1069.  
  1070.     if( !pComboBox->ContainsItem( strRefreshRate ) )
  1071.         pComboBox->AddItem( strRefreshRate, ULongToPtr(dwRate) );
  1072. }
  1073.  
  1074.  
  1075. //-------------------------------------------------------------------------------------
  1076. DWORD CD3DSettingsDlg::GetSelectedRefreshRate()
  1077. {
  1078.     CDXUTComboBox* pComboBox = m_Dialog.GetComboBox( DXUTSETTINGSDLG_REFRESH_RATE );
  1079.     
  1080.     return PtrToUlong( pComboBox->GetSelectedData() );
  1081. }
  1082.  
  1083.  
  1084. //-------------------------------------------------------------------------------------
  1085. void CD3DSettingsDlg::AddBackBufferFormat( D3DFORMAT format )
  1086. {
  1087.     CDXUTComboBox* pComboBox = m_Dialog.GetComboBox( DXUTSETTINGSDLG_BACK_BUFFER_FORMAT );
  1088.     
  1089.     if( !pComboBox->ContainsItem( DXUTD3DFormatToString(format, TRUE) ) )
  1090.         pComboBox->AddItem( DXUTD3DFormatToString(format, TRUE), ULongToPtr( format ) );
  1091. }
  1092.  
  1093.  
  1094. //-------------------------------------------------------------------------------------
  1095. D3DFORMAT CD3DSettingsDlg::GetSelectedBackBufferFormat()
  1096. {
  1097.     CDXUTComboBox* pComboBox = m_Dialog.GetComboBox( DXUTSETTINGSDLG_BACK_BUFFER_FORMAT );
  1098.     
  1099.     return (D3DFORMAT) PtrToUlong( pComboBox->GetSelectedData() ); 
  1100. }
  1101.  
  1102.  
  1103. //-------------------------------------------------------------------------------------
  1104. void CD3DSettingsDlg::AddDepthStencilBufferFormat( D3DFORMAT format )
  1105. {
  1106.     CDXUTComboBox* pComboBox = m_Dialog.GetComboBox( DXUTSETTINGSDLG_DEPTH_STENCIL );
  1107.     
  1108.     if( !pComboBox->ContainsItem( DXUTD3DFormatToString(format, TRUE) ) )
  1109.         pComboBox->AddItem( DXUTD3DFormatToString(format, TRUE), ULongToPtr(format) );
  1110. }
  1111.  
  1112.  
  1113. //-------------------------------------------------------------------------------------
  1114. D3DFORMAT CD3DSettingsDlg::GetSelectedDepthStencilBufferFormat()
  1115. {
  1116.     CDXUTComboBox* pComboBox = m_Dialog.GetComboBox( DXUTSETTINGSDLG_DEPTH_STENCIL );
  1117.     
  1118.     return (D3DFORMAT) PtrToUlong( pComboBox->GetSelectedData() ); 
  1119. }
  1120.  
  1121.  
  1122. //-------------------------------------------------------------------------------------
  1123. void CD3DSettingsDlg::AddMultisampleType( D3DMULTISAMPLE_TYPE type )
  1124. {
  1125.     CDXUTComboBox* pComboBox = m_Dialog.GetComboBox( DXUTSETTINGSDLG_MULTISAMPLE_TYPE );
  1126.     
  1127.     if( !pComboBox->ContainsItem( DXUTMultisampleTypeToString(type) ) )
  1128.         pComboBox->AddItem( DXUTMultisampleTypeToString(type), ULongToPtr(type) );
  1129. }
  1130.  
  1131.  
  1132. //-------------------------------------------------------------------------------------
  1133. D3DMULTISAMPLE_TYPE CD3DSettingsDlg::GetSelectedMultisampleType()
  1134. {
  1135.     CDXUTComboBox* pComboBox = m_Dialog.GetComboBox( DXUTSETTINGSDLG_MULTISAMPLE_TYPE );
  1136.     
  1137.     return (D3DMULTISAMPLE_TYPE) PtrToUlong( pComboBox->GetSelectedData() ); 
  1138. }
  1139.  
  1140.  
  1141. //-------------------------------------------------------------------------------------
  1142. void CD3DSettingsDlg::AddMultisampleQuality( DWORD dwQuality )
  1143. {
  1144.     CDXUTComboBox* pComboBox = m_Dialog.GetComboBox( DXUTSETTINGSDLG_MULTISAMPLE_QUALITY );
  1145.         
  1146.     WCHAR strQuality[50];
  1147.     _snwprintf( strQuality, 50, L"%d", dwQuality );
  1148.     strQuality[49] = 0;
  1149.  
  1150.     if( !pComboBox->ContainsItem( strQuality ) )
  1151.         pComboBox->AddItem( strQuality, ULongToPtr(dwQuality) );
  1152. }
  1153.  
  1154.  
  1155. //-------------------------------------------------------------------------------------
  1156. DWORD CD3DSettingsDlg::GetSelectedMultisampleQuality()
  1157. {
  1158.     CDXUTComboBox* pComboBox = m_Dialog.GetComboBox( DXUTSETTINGSDLG_MULTISAMPLE_QUALITY );
  1159.     
  1160.     return PtrToUlong( pComboBox->GetSelectedData() ); 
  1161. }
  1162.  
  1163.  
  1164. //-------------------------------------------------------------------------------------
  1165. void CD3DSettingsDlg::AddVertexProcessingType( DWORD dwType )
  1166. {
  1167.     CDXUTComboBox* pComboBox = m_Dialog.GetComboBox( DXUTSETTINGSDLG_VERTEX_PROCESSING );
  1168.     
  1169.     if( !pComboBox->ContainsItem( DXUTVertexProcessingTypeToString(dwType) ) )
  1170.         pComboBox->AddItem( DXUTVertexProcessingTypeToString(dwType), ULongToPtr(dwType) );
  1171. }
  1172.  
  1173.  
  1174. //-------------------------------------------------------------------------------------
  1175. DWORD CD3DSettingsDlg::GetSelectedVertexProcessingType()
  1176. {
  1177.     CDXUTComboBox* pComboBox = m_Dialog.GetComboBox( DXUTSETTINGSDLG_VERTEX_PROCESSING );
  1178.     
  1179.     return PtrToUlong( pComboBox->GetSelectedData() ); 
  1180. }
  1181.  
  1182.  
  1183. //-------------------------------------------------------------------------------------
  1184. void CD3DSettingsDlg::AddPresentInterval( DWORD dwInterval )
  1185. {
  1186.     CDXUTComboBox* pComboBox = m_Dialog.GetComboBox( DXUTSETTINGSDLG_PRESENT_INTERVAL );
  1187.     
  1188.     if( !pComboBox->ContainsItem( DXUTPresentIntervalToString(dwInterval) ) )
  1189.         pComboBox->AddItem( DXUTPresentIntervalToString(dwInterval), ULongToPtr(dwInterval) );
  1190. }
  1191.  
  1192.  
  1193. //-------------------------------------------------------------------------------------
  1194. DWORD CD3DSettingsDlg::GetSelectedPresentInterval()
  1195. {
  1196.     CDXUTComboBox* pComboBox = m_Dialog.GetComboBox( DXUTSETTINGSDLG_PRESENT_INTERVAL );
  1197.     
  1198.     return PtrToUlong( pComboBox->GetSelectedData() ); 
  1199. }
  1200.  
  1201.  
  1202. //-------------------------------------------------------------------------------------
  1203. void CD3DSettingsDlg::SetDeviceClip( bool bDeviceClip )
  1204. {
  1205.     CDXUTCheckBox* pCheckBox = m_Dialog.GetCheckBox( DXUTSETTINGSDLG_DEVICECLIP );
  1206.     pCheckBox->SetChecked( bDeviceClip );
  1207. }
  1208.  
  1209.  
  1210. //-------------------------------------------------------------------------------------
  1211. bool CD3DSettingsDlg::IsDeviceClip()
  1212. {
  1213.     CDXUTCheckBox* pCheckBox = m_Dialog.GetCheckBox( DXUTSETTINGSDLG_DEVICECLIP );
  1214.     return pCheckBox->GetChecked();
  1215. }
  1216.  
  1217.  
  1218. //--------------------------------------------------------------------------------------
  1219. // Returns the string for the given D3DDEVTYPE.
  1220. //--------------------------------------------------------------------------------------
  1221. WCHAR* DXUTD3DDeviceTypeToString(D3DDEVTYPE devType)
  1222. {
  1223.     switch (devType)
  1224.     {
  1225.         case D3DDEVTYPE_HAL:        return L"D3DDEVTYPE_HAL";
  1226.         case D3DDEVTYPE_SW:         return L"D3DDEVTYPE_SW";
  1227.         case D3DDEVTYPE_REF:        return L"D3DDEVTYPE_REF";
  1228.         default:                    return L"Unknown devType";
  1229.     }
  1230. }
  1231.  
  1232.  
  1233. //--------------------------------------------------------------------------------------
  1234. // Returns the string for the given D3DMULTISAMPLE_TYPE.
  1235. //--------------------------------------------------------------------------------------
  1236. WCHAR* DXUTMultisampleTypeToString(D3DMULTISAMPLE_TYPE MultiSampleType)
  1237. {
  1238.     switch (MultiSampleType)
  1239.     {
  1240.     case D3DMULTISAMPLE_NONE:       return L"D3DMULTISAMPLE_NONE";
  1241.     case D3DMULTISAMPLE_NONMASKABLE: return L"D3DMULTISAMPLE_NONMASKABLE";
  1242.     case D3DMULTISAMPLE_2_SAMPLES:  return L"D3DMULTISAMPLE_2_SAMPLES";
  1243.     case D3DMULTISAMPLE_3_SAMPLES:  return L"D3DMULTISAMPLE_3_SAMPLES";
  1244.     case D3DMULTISAMPLE_4_SAMPLES:  return L"D3DMULTISAMPLE_4_SAMPLES";
  1245.     case D3DMULTISAMPLE_5_SAMPLES:  return L"D3DMULTISAMPLE_5_SAMPLES";
  1246.     case D3DMULTISAMPLE_6_SAMPLES:  return L"D3DMULTISAMPLE_6_SAMPLES";
  1247.     case D3DMULTISAMPLE_7_SAMPLES:  return L"D3DMULTISAMPLE_7_SAMPLES";
  1248.     case D3DMULTISAMPLE_8_SAMPLES:  return L"D3DMULTISAMPLE_8_SAMPLES";
  1249.     case D3DMULTISAMPLE_9_SAMPLES:  return L"D3DMULTISAMPLE_9_SAMPLES";
  1250.     case D3DMULTISAMPLE_10_SAMPLES: return L"D3DMULTISAMPLE_10_SAMPLES";
  1251.     case D3DMULTISAMPLE_11_SAMPLES: return L"D3DMULTISAMPLE_11_SAMPLES";
  1252.     case D3DMULTISAMPLE_12_SAMPLES: return L"D3DMULTISAMPLE_12_SAMPLES";
  1253.     case D3DMULTISAMPLE_13_SAMPLES: return L"D3DMULTISAMPLE_13_SAMPLES";
  1254.     case D3DMULTISAMPLE_14_SAMPLES: return L"D3DMULTISAMPLE_14_SAMPLES";
  1255.     case D3DMULTISAMPLE_15_SAMPLES: return L"D3DMULTISAMPLE_15_SAMPLES";
  1256.     case D3DMULTISAMPLE_16_SAMPLES: return L"D3DMULTISAMPLE_16_SAMPLES";
  1257.     default:                        return L"Unknown Multisample Type";
  1258.     }
  1259. }
  1260.  
  1261.  
  1262. //--------------------------------------------------------------------------------------
  1263. // Returns the string for the given vertex processing type
  1264. //--------------------------------------------------------------------------------------
  1265. WCHAR* DXUTVertexProcessingTypeToString(DWORD vpt)
  1266. {
  1267.     switch (vpt)
  1268.     {
  1269.     case D3DCREATE_SOFTWARE_VERTEXPROCESSING: return L"Software vertex processing";
  1270.     case D3DCREATE_MIXED_VERTEXPROCESSING:    return L"Mixed vertex processing";
  1271.     case D3DCREATE_HARDWARE_VERTEXPROCESSING: return L"Hardware vertex processing";
  1272.     case D3DCREATE_PUREDEVICE:                return L"Pure hardware vertex processing";
  1273.     default:                                  return L"Unknown vertex processing type";
  1274.     }
  1275. }
  1276.  
  1277.  
  1278. //--------------------------------------------------------------------------------------
  1279. // Returns the string for the given present interval.
  1280. //--------------------------------------------------------------------------------------
  1281. WCHAR* DXUTPresentIntervalToString( UINT pi )
  1282. {
  1283.     switch( pi )
  1284.     {
  1285.     case D3DPRESENT_INTERVAL_IMMEDIATE: return L"D3DPRESENT_INTERVAL_IMMEDIATE";
  1286.     case D3DPRESENT_INTERVAL_DEFAULT:   return L"D3DPRESENT_INTERVAL_DEFAULT";
  1287.     case D3DPRESENT_INTERVAL_ONE:       return L"D3DPRESENT_INTERVAL_ONE";
  1288.     case D3DPRESENT_INTERVAL_TWO:       return L"D3DPRESENT_INTERVAL_TWO";
  1289.     case D3DPRESENT_INTERVAL_THREE:     return L"D3DPRESENT_INTERVAL_THREE";
  1290.     case D3DPRESENT_INTERVAL_FOUR:      return L"D3DPRESENT_INTERVAL_FOUR";
  1291.     default:                            return L"Unknown PresentInterval";
  1292.     }
  1293. }
  1294.  
  1295.  
  1296.